package com.wsm.springai.studydemo2.gh;

import com.alibaba.cloud.ai.autoconfigure.dashscope.DashScopeChatProperties;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import com.wsm.springai.studydemo2.tools.ToolService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatClientBean {
    ChatClient chatClient;


    public ChatClientBean(ChatClient.Builder chatClientBuilder,
                          GhInfoService ghInfoService,
                          DashScopeChatProperties options,
                          ChatMemory chatMemory) {
        DashScopeChatOptions dashScopeChatOptions = DashScopeChatOptions.fromOptions(options.getOptions());
        // 设置温度
        dashScopeChatOptions.setTemperature(0.5);
        chatClient = chatClientBuilder.defaultTools(ghInfoService)
                .defaultAdvisors(PromptChatMemoryAdvisor.builder(chatMemory).build() , new SimpleLoggerAdvisor())
                .defaultSystem("""
                        你是WSM医院的智能客服，处理用户的查询、退票等服务，请友好的处理用户的请求。
                        """)
                .build();
    }
}
